



//
//  NGovDeskViewController.m
//  nncloud
//
//  Created by macfai on 2018/9/19.
#import "NEnterpriseSearchVC.h"
#import "NGovDataInqueryViewController.h"
#import "NDataInqueryViewController.h"
#import "NBigDataApplyCommontVC.h"
#import "NQiyeSumViewController.h"
#import "NMyQiyeViewController.h"
#import "NTongjiViewController.h"
#import "NCaiWuViewController.h"
#import "NIndustryReportFormViewController.h"
#import "NGovOnlineViewController.h"
#import "NZhichengPingshenVC.h"
#import "NGovDeskViewController.h"
#import "NServeCell.h"
#import "NGovReceivedProblemFBViewController.h"
#import "NProcessInstrucitonViewController.h"
#import "NWorkStatistisViewController.h"
#import "NNGAnalysisViewController.h"
#import "NInovationCommonViewController.h"
#import "NQiyeRecruitVC.h"
#import "NQiyebanshiViewController.h"
#import "NQiuzhiMsgViewController.h"
#import "NProjectShenbaoViewController.h"
#import "NMessageViewController.h"
@interface NGovDeskViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)NSMutableArray *dataArry;

@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) NSArray *titleArray1;
@property (nonatomic,strong) NSArray *titleArray2;
@property (nonatomic,strong) NSArray *titleArray3;

@property (nonatomic,strong) NSArray *iconArray;
@property (nonatomic,strong) NSArray *iconArray1;
@property (nonatomic,strong) NSArray *iconArray2;
@property (nonatomic,strong) NSArray *iconArray3;

@property (nonatomic,strong) NSArray *titleArray4;

@property (nonatomic,strong) NSArray *iconArray4;

@property (nonatomic,strong) NSArray *sectionTitleArray;

@end


@implementation NGovDeskViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    ///控制红点显示
    if ([NUserModel shareInstance].isLogin) {
        if ([[NUserModel shareInstance].badgeCount integerValue]>0) {
            [self.navigationItem.rightBarButtonItem pp_addDotWithColor:[UIColor redColor]];
        }
    }else{
        [self.navigationItem.rightBarButtonItem pp_addDotWithColor:nil];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = nil;
    self.view.backgroundColor = kWhiteColor;
    [self.navigationItem setItemWithTitle:@"工作台" textColor:kNavigationTitleColor fontSize:18 itemType:center];
     [self addNavgationRightButtonWithFrame:CGRectMake(0, 0, 40, 40) title:@"" Image:@"消息中心" selectedIMG:@"消息中心" tartget:self action:@selector(messageAction)];
    
//    if ([NUserModel shareInstance].isLogin) {
//        if ([[NUserModel shareInstance].badgeCount integerValue]>0) {
//
//            [self.navigationItem.rightBarButtonItem pp_addDotWithColor:[UIColor redColor]];
//        }
//    }
    [self data];
    [self.view addSubview:self.collectionView];
    // Do any additional setup after loading the view from its nib.
}

///消息中心
- (void)messageAction {
    YYLog(@"跳往消息中心");
    NMessageViewController *msg = [NMessageViewController new];
    msg.userType = [NUserModel shareInstance].userInfoType;
    msg.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:msg animated:YES];
}
- (void)data {
    self.sectionTitleArray = @[@"营商环境",@"大数据应用",@"工业运行监测",@"创新创业",@"企业服务"];
    self.titleArray = @[@"处理中反馈",@"已处理反馈",@"工作统计",@"常见问题"];
    self.iconArray = @[@"问题3",@"未标题-2",@"未标题-3",@"未标题-4"];
    
    self.titleArray1 = @[@"产业地图",@"政府决策指数",@"创新能力应用",@"创新态势",@"企业图谱",];
    self.iconArray1 = @[@"未标题-5",@"未标题-6",@"未标题-8",@"创新态势",@"企业图谱",];
    
    self.titleArray2 = @[@"工业企业汇总",@"工业报表",@"财务报表",@"项目申报",@"统计分析",@"数据查询"];
    self.iconArray2 =  @[@"我的企业",@"我的工业填报",@"我的财务填报",@"我的项目申报",@"统计分析",@"数据查询"];
    
    self.titleArray3 = @[@"智慧招商",@"创新创业项目",@"知识产权服务",@"项目申报",@"培训服务",@"科技金融",@"项目路演"];
    self.iconArray3 = @[@"智慧招商",@"创新创业项目",@"知识产权服务",@"项目申报",@"培训服务",@"科技金融",@"项目路演"];
    
    self.titleArray4 = @[@"企业办事",@"企业招聘",@"求职信息",@"政府在线",@"职称评审"];
    self.iconArray4 =@[@"企业办事",@"企业招聘",@"求职信息",@"政府在线",@"职称评审"];
}

//流式布局
- (UICollectionViewFlowLayout *)flowLayout {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    
    layout.sectionInset = UIEdgeInsetsMake(15, 0, 0, 0);
    layout.minimumLineSpacing = 0.f;
    layout.minimumInteritemSpacing = 0.f;
    //    layout.headerReferenceSize = CGSizeMake(kScreenWidth, SectionHeaderHeight);
    return layout;
}

- (UICollectionView *)collectionView {
    
    if (!_collectionView) {
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-64-50) collectionViewLayout:[self flowLayout]];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.showsVerticalScrollIndicator = NO;
        [self registerCell];
        //        WeakStament(ws);
        //        _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //            [ws refreshData];
        //        }];
        _collectionView.backgroundColor = kWhiteColor;
    }
    return _collectionView;
}

- (void)registerCell {
    
    [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([NServeCell class]) bundle:nil] forCellWithReuseIdentifier:@"serveid"];
    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headReuse"];
    
}

#pragma  mark - datasource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 5;
    
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    switch (section) {
            
        case 0:
        {
            return 4;
        }
            break;
        case 1:
        {
            return 5;
        }
            break;
        case 2:
            {
                return self.titleArray2.count;
            }
            break;
        case 4:
        {
            return 5;
        }
            break;
        case 3:
        {
            return 7;
        }
            break;
        default:
            break;
    }
    return 0;
}

-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NServeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"serveid" forIndexPath:indexPath];
    
    if (indexPath.section==0) {
        
        cell.nameLabel.text = self.titleArray[indexPath.row];
        cell.iconImage.image = WDImgName(self.iconArray[indexPath.row]);
        
    }else if(indexPath.section==1){
        
        cell.nameLabel.text = self.titleArray1[indexPath.row];
        cell.iconImage.image = WDImgName(self.iconArray1[indexPath.row]);
        
    }else if (indexPath.section==2){
        
        cell.nameLabel.text = self.titleArray2[indexPath.row];
        cell.iconImage.image = WDImgName(self.iconArray2[indexPath.row]);
        
    }else if (indexPath.section==3){
        
        cell.nameLabel.text = self.titleArray3[indexPath.row];
        cell.iconImage.image = WDImgName(self.iconArray3[indexPath.row]);
        
    }else{
        cell.nameLabel.text = self.titleArray4[indexPath.row];
        cell.iconImage.image = WDImgName(self.iconArray4[indexPath.row]);
    }
    return cell;
    
    
}

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    UICollectionReusableView *reusabelView = nil;
    
    //    XALifeListModel *model = self.dataArray[indexPath.section-BannerIndex];
    if (kind == UICollectionElementKindSectionHeader) {
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 65)];
        
        bgView.backgroundColor = [UIColor clearColor];
        
        UIView *sepratorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 11)];
        sepratorView.backgroundColor = NColorFrom16RGB(0xeeeeee);
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, ScreenWidth, 65-5)];
        
        //titleLabel.text = model.title;
        titleLabel.text = self.sectionTitleArray[indexPath.section];
        UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headReuse" forIndexPath:indexPath];
        [headerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
        [headerView addSubview:bgView];
        [headerView addSubview:sepratorView];
        [headerView addSubview:titleLabel];
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 65-6, ScreenWidth, 1)];
        line.backgroundColor = NColorFrom16RGB(0xeeeeee);
        [headerView addSubview:line];
        reusabelView = headerView;
    }
    return reusabelView;
}

#pragma mark - delegate
//cell尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CGFloat width=ScreenWidth/4.0;
    return CGSizeMake(width, width);
}


///section header 尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    return CGSizeMake(ScreenWidth, 65-20);
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    //    XALifeListModel *model = self.dataArray[indexPath.section-BannerIndex];
    //    XAListContentModel *smodel = model.content[indexPath.row];
    //    [self skipWithModel:smodel];
    
    if (indexPath.section==0) {
        
        switch (indexPath.row) {
            case 0:
            {
                if ([NUserModel shareInstance].isLogin) {
                    NGovReceivedProblemFBViewController *govFb = [NGovReceivedProblemFBViewController new];
                     [NUserModel shareInstance].index = 0;
                    govFb.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:govFb animated:YES];
                }else{
                    [self callLoginVC];
                }
                
            }
                break;
                
            case 1:
            {
                
                 if ([NUserModel shareInstance].isLogin) {
                     NGovReceivedProblemFBViewController *govFb = [NGovReceivedProblemFBViewController new];
                     [NUserModel shareInstance].index = 2;
                     govFb.hidesBottomBarWhenPushed = YES;
                     [self.navigationController pushViewController:govFb animated:YES];
                     
                 }else{
                      [self callLoginVC];
                 }
               
            }
                break;
            case 2:
            {
                
                     NNGAnalysisViewController *analysis = [NNGAnalysisViewController new];
                     analysis.month = 10;
                     analysis.webUrl = @"";
                     analysis.flag = @"stat";
                     analysis.hidesBottomBarWhenPushed = YES;
                     [self.navigationController pushViewController:analysis animated:YES];
               
            }
                break;
            case 3:
            {
                NProcessInstrucitonViewController *proc = [NProcessInstrucitonViewController new];
                proc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:proc animated:YES];
            }
                break;
                
            default:
                break;
        }
        
        
    }else if (indexPath.section==1){
        
        NBigDataApplyCommontVC *data = [NBigDataApplyCommontVC new];
        data.hidesBottomBarWhenPushed = YES;
        
        
        ///大数据应用
        switch (indexPath.row) {
            case 0:
            {
                data.url = @"http://211.149.207.217/Nanning_DP/#/";
                
            }
                break;
            case 1:
            {
                
                data.url = @"http://cdyoue.com.cn:18182/visualization/bigData/html/investmentSituatioin.html";
                
            }
                break;
                
            case 2:
            {
                
                data.url = @"http://cdyoue.com.cn:18182/cxnl/";
                
            }
                break;
                
            case 3:
            {
                ///创新态势
                data.url = @"http://cdyoue.com.cn:18182/cxst/index.html";
            }
               
                break;
                
            case 4:
            {
                
                //企业图谱
                data.url = @"http://cdyoue.com.cn:18182/visualization/bigData/html/enterpriseAtlas.html";
            }
                break;
                
            default:
                break;
                
        }
        
        [self.navigationController pushViewController:data animated:YES];
    }
    else if (indexPath.section==2){
        
        switch (indexPath.row) {
            case 0:
            {
                NQiyeSumViewController *qiye = [NQiyeSumViewController new];
                qiye.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:qiye animated:YES];
            }
                break;
            case 1:
            {
                NIndustryReportFormViewController *data = [NIndustryReportFormViewController new];
                data.hidesBottomBarWhenPushed = YES;
                data.userType = [NUserModel shareInstance].userInfoType;
                [NUserModel shareInstance].isIndustryTable = YES;
                [self.navigationController pushViewController:data animated:YES];
            }
                break;
            case 2:
            {
                NCaiWuViewController *caiwu = [NCaiWuViewController new];
                caiwu.hidesBottomBarWhenPushed = YES;
                 [NUserModel shareInstance].isIndustryTable = NO;
                [self.navigationController pushViewController:caiwu animated:YES];
            }
                
                break;
            case 3:
            {
                
                NProjectShenbaoViewController *shenbao = [NProjectShenbaoViewController new];
                shenbao.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:shenbao animated:YES];
                
            }
                
                break;
                
            case 4:
            {
                //统计分析
                NTongjiViewController *tongji = [NTongjiViewController new];
                tongji.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:tongji animated:YES];
                
            }
                break;
                
            case 5:
            {
                
                NGovDataInqueryViewController *tongji = [NGovDataInqueryViewController new];
                tongji.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:tongji animated:YES];
                
            }
                break;
            default:
                break;
        }
        
    }else if (indexPath.section==3){
        
            NInovationCommonViewController *common = [NInovationCommonViewController new];
            
            switch (indexPath.row) {
                    
                case 0:
                {
                    common.atitle = @"智慧招商";
                }
                    break;
                case 1:
                {
                    common.atitle = @"创新创业";
                }
                    break;
                case 2:
                {
                    common.atitle = @"知识产权";
                }
                    break;
                case 3:
                {
                    common.atitle = @"项目申报";
                }
                    break;
                case 4:
                {
                    common.atitle = @"培训服务";
                }
                    break;
                case 5:
                {
                    common.atitle = @"融资服务";
                }
                    break;
                case 6:
                {
                    common.atitle = @"项目路演";
                }
                    break;
                default:
                    break;
            }
            common.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:common animated:YES];
            
        
    }else{
        
        //企业服务
        switch (indexPath.row) {
            case 0:
            {
                NQiyebanshiViewController *banshi = [NQiyebanshiViewController new];
                banshi.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:banshi animated:YES];
            }
                break;
            case 1:
            {
                NQiyeRecruitVC *recruit = [NQiyeRecruitVC new];
                recruit.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:recruit animated:YES];
            }
                break;
            case 2:
            {
                NQiuzhiMsgViewController *msg = [NQiuzhiMsgViewController new];
                msg.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:msg animated:YES];
                
            }
                break;
            case 3:
            {
                NGovOnlineViewController *gov = [NGovOnlineViewController new];
                gov.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:gov animated:YES];
            }
                break;
            case 4:
            {
                NZhichengPingshenVC *zhicheng = [NZhichengPingshenVC new];
                zhicheng.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:zhicheng animated:YES];
            }
                break;
                
            default:
                break;
        }
    }
    
}

@end
